package treeview;

import search.Visitor;

import java.awt.*;

/**
 * Created by Pavel Nikolaev
 */
public abstract class AbstractNodeView implements NodeView {
    protected int myWidth = 0;
    protected int myHeight = 0;
    protected int myX = 0;
    protected int myY = 0;

    public int getX() {
        return myX;
    }

    public int getY() {
        return myY;
    }

    public boolean intersect(int x, int y) {
        boolean result = (x >= myX);
        result &= (x < myX + myWidth);
        result &= (y >= myY);
        result &= (y < myY + myHeight);
        return result;
    }

    public void setLocation(int x, int y) {
        myX = x;
        myY = y;
    }

    public void drawAt(Graphics g, int x, int y) {
        myX = x;
        myY = y;
        paint(g);
    }

    public int getHeight() {
        return myHeight;
    }

    public int getWidth() {
        return myWidth;
    }

    public void setHeight(int height) {
        myHeight = height;
    }

    public void setWidth(int width) {
        myWidth = width;
    }

    public void print(int level) {
        for(int i = 0; i < level; ++i) System.out.print('\t');
        System.out.print("[");
        System.out.print(myWidth);
        System.out.print(" ");
        System.out.print(myHeight);
        System.out.print("] ");
        System.out.println(toString());
    }

    // methods with empty implementation
    public void setDescent(int descent) {/*ignored*/}
    public int getDescent() {return 0;}
    public void setAscent(int ascent) {/*ignored*/}
    public int getAscent() {return 0;}
    public int countChildren() {return 0;}
    public NodeView getChild(int index) {return null;}
    public void accept(Visitor visitor) {/*ignored*/}
}
